package com.xiaoxin.suma.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.xiaoxin.suma.R;
import com.xiaoxin.suma.fragment.GetCodeFragment;
import com.xiaoxin.suma.fragment.GetProgramFragment;
import com.xiaoxin.suma.fragment.UserFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MainActivity extends BaseActivity {

    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    List<Fragment> fragments;
    List<String> tabs;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public boolean showActionBar() {
        return false;
    }

    @Override
    protected void initData() {
        super.initData();
        tabs = new ArrayList<>();
        fragments = new ArrayList<>();
        fragments.add(new GetCodeFragment());
        fragments.add(new GetProgramFragment());
        fragments.add(new UserFragment());
        tabs.add("获取验证码");
        tabs.add("获取项目");
        tabs.add("我的");
    }

    @Override
    protected void initView() {
        super.initView();
        vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return tabs.get(position % 3);
            }
        });
        tablayout.setupWithViewPager(vp);
    }
}
